<template>
    <div class="app-container">
        <!-- UserPoliAppl RelatedCases-->
        <el-form ref="queryParamsRef" :inline="true" label-width="100" :model="queryParams">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-form-item label="部门受案号-关联案件">
                        <el-input v-model="queryParams.casecode" clearable @clear="getTableDataLists" style="width: 13vw;"/>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="案件名称">
                        <el-input v-model="queryParams.name" 
                        clearable 
                        @clear="getTableDataLists" 
                        @keyup.enter.prevent="getTableDataLists"
                        style="width: 13vw;"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="所在赃证物柜">
                        <el-input v-model="queryParams.name" 
                        clearable 
                        @clear="getTableDataLists" 
                        @keyup.enter.prevent="getTableDataLists"
                        style="width: 13vw;"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="入库日期">
                        <el-date-picker
                            v-model="dateRange"
                            value-format="YYYY-MM-DD"
                            type="daterange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            style="width:13vw"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="状态">
                        <el-select
                            v-model="queryParams.status"
                            placeholder="用户状态"
                            clearable
                            style="width: 13vw"
                        >
                            <el-option
                                v-for="dict in sys_normal_disable"
                                :key="dict.value"
                                :label="dict.label"
                                :value="dict.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item>
                        <el-button type="primary" @click="getTableDataLists">
                            <el-icon class="me-1">
                                <Search/>
                            </el-icon>
                            查询
                        </el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="handleRest">
                            <el-icon class="me-1">
                                <Refresh/>
                            </el-icon>
                            重置
                        </el-button>
                    </el-form-item>
                </el-col>
                
            </el-row>
        </el-form>
        <el-divider class="mt-0 mb-3"/>
        <el-row class="mb-3" style="color: #DC362E;">
            本次条件查询结果：2099件， 5860册
        </el-row>
        <el-row class="mb-3">
            <el-col :span="24">
                <el-space>
                    <el-button
                        plain
                        type="primary"
                        @click="RelatedCasesRef.showAddEditCase()"
                    >
                        <el-icon class="me-2">
                            <Plus/>
                        </el-icon>
                        新增
                    </el-button>
                </el-space>
            </el-col>
        </el-row>
        <el-table
            ref="TableDataRef"
            v-loading="loading"
            :data="TablesData"
            show-overflow-tooltip
        >
            <el-table-column label="部门受案号" prop="name"/>
            <el-table-column label="案件名称" prop="casetype"/>
            
            <el-table-column label="承办人" prop="userName"/>
            <el-table-column label="入库日期" prop="casetype"/>
            <el-table-column label="赃证物类别" prop="state">
                <template #default="scope">
                    <dict-tag :options="nj_anjian_status" :value="scope.row.state"/>
                </template>
            </el-table-column>
            <el-table-column label="超高屏RFID码" prop="casetype"/>
            <el-table-column label="条码" prop="casetype"/>
            <el-table-column label="所在赃证物柜" prop="casetype"/>
            <el-table-column label="状态" prop="state">
                <template #default="scope">
                    <dict-tag :options="nj_anjian_status" :value="scope.row.state"/>
                </template>
            </el-table-column>
            <el-table-column fixed="right" align="center" label="操作" width="200">
                <template #default="scope">
                    <el-button
                        link size="small"
                        type="primary"
                        @click="RelatedCasesRef.showEditCase(scope.row,'edit')"
                        >
                        <el-icon class="me-1">
                            <Edit/>
                        </el-icon>
                        编辑
                    </el-button>
                    <el-button
                        link size="small"
                        type="primary"
                        @click="RelatedCasesRef.showEditCase(scope.row,'detail')"
                        >
                        <el-icon class="me-1">
                            <Edit/>
                        </el-icon>
                        详情
                    </el-button>
                    <el-button
                        link size="small"
                        type="danger"
                        @click="deleteData(scope.row)">
                        <el-icon class="me-1">
                            <Delete/>
                        </el-icon>
                        删除
                    </el-button>    
                </template>
            </el-table-column>
        </el-table>
        <pagination
            v-show="total > 0"
            :total="total"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getTableDataLists"
        />
        <RelatedCases ref="RelatedCasesRef" @getList="getTableDataLists" />
    </div>
</template>

<script setup>
const {proxy} = getCurrentInstance();
import RelatedCases from "@/components/Case/RelatedCases.vue";
// import {getCaseInfoList,getCaseInfoInfo,  deleteCaseInfo} from "@/api/CaseInfo/CaseInfo";
import PageEnum from "@/enum/PageEnum.js";

const {sys_normal_disable,nj_anjian_status} = proxy.useDict('sys_normal_disable', 'nj_anjian_status')

const queryParamsRef = ref()
const RelatedCasesRef = ref({})
const loading = ref(false)
const dateRange = ref([])

const queryParams = ref({
    name: '',
    casecode: '',
     // 页码
     pageNum: 1,
    // 分页数量
    pageSize: PageEnum.SIZE
})

const total = ref(0)
const TablesData = ref([{
    name:'111',
}])

onMounted(() => {
    // getTableDataLists()
})

// 获取案件列表
const getTableDataLists = async () => {
    proxy.$modal.msgSuccess("获取案件");
    // loading.value = true
    // await getCaseInfoList(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    //     loading.value = false;
    //     TablesData.value = res.rows
    //     total.value = res.total;
    // });
}
const TableDataRef = ref()

const deleteData = async (row) => {
    ElMessageBox.confirm('确定删除此案件？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    deleteCaseInfo(row.caseCaseinfoId).then(res => {
        getTableDataLists()
    })
  }).catch(() => {
  });
}

// 重置搜索调解
const handleRest = () => {
    queryParams.value = {
        name: '',
        casecode: '',
    }
    getTableDataLists()
}
</script>

<style lang="scss" scoped>

</style>